/**
 * Copyright (C) 2018-2019
 * All rights reserved, Designed By www.joolun.com
 */
package com.joolun.web.controller.mall;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.mall.entity.Video;
import com.joolun.mall.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 视频回放
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/video")
@Api(value = "video", tags = "视频回放")
public class VideoController extends BaseController {

    private final VideoService baseService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param entity 视频回放
    * @return
    */
	@ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPermi('mall:video:index')")
    public AjaxResult getWishPage(Page page, Video entity) {
        return AjaxResult.success(baseService.page1(page,entity));
    }

    /**
    * 通过id查询视频回放
    * @param id
    * @return R
    */
	@ApiOperation(value = "通过id查询视频回放")
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('mall:video:get')")
    public AjaxResult getById(@PathVariable("id") String id){
        return AjaxResult.success(baseService.getById(id));
    }

    /**
    * 新增视频回放
    * @param entity 视频回放
    * @return R
    */
	@ApiOperation(value = "新增视频回放")
    @PostMapping
    @PreAuthorize("@ss.hasPermi('mall:video:add')")
    public AjaxResult save(@RequestBody Video entity){
        entity.setCreateTime(LocalDateTime.now());
        return AjaxResult.success(baseService.save(entity));
    }

    /**
    * 修改视频回放
    * @param entity 视频回放
    * @return R
    */
	@ApiOperation(value = "修改视频回放")
    @PutMapping
    @PreAuthorize("@ss.hasPermi('mall:video:edit')")
    public AjaxResult updateById(@RequestBody Video entity){
        return AjaxResult.success(baseService.updateById(entity));
    }

    /**
    * 通过id删除视频回放
    * @param id
    * @return R
    */
	@ApiOperation(value = "通过id删除视频回放")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('mall:video:del')")
    public AjaxResult removeById(@PathVariable String id){
        return AjaxResult.success(baseService.removeById(id));
    }

}
